package org.uugu.util;

import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

public class LoginFilter extends MethodFilterInterceptor {  
    private static final long serialVersionUID = 1358600090729208361L;  
  
    //拦截Action处理的拦截方法
    @Override
    public String doIntercept(ActionInvocation invocation) throws Exception {  
        // 取得请求相关的ActionContext实例  
        ActionContext ctx=invocation.getInvocationContext();  
        Map session=ctx.getSession();  
        //取出名为user的session属性  
        String user=(String)session.get("user");  
        //如果没有登陆，都返回重新登陆  
        System.out.println("=============="+user);
        if(user!=null){ 
        	System.out.println("拦截通过！");
            return invocation.invoke();  
        }  
        //没有登陆，将服务器提示设置成一个HttpServletRequest属性  
        ctx.put("tip","您还没有登录，请登陆系统"); 
        
        return Action.ERROR;       
    }

} 